home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / internet / amitcp3.0b / src.lha / src / amitcp / api / auto_socket.c < prev    next >
Encoding:
Text File  |  1996-09-08  |  45.1 KB  |  1,140 lines

  1. /****** bsdsocket.library/accept ********************************************
  2. *
  3. *   NAME
  4. *        accept - accept a connection on a socket
  5. *
  6. *   SYNOPSIS
  7. *        #include <sys/types.h>
  8. *        #include <sys/socket.h>
  9. *
  10. *        ns = accept(s, addr, addrlen)
  11. *        D0          D0 A0    A1
  12. *
  13. *        long accept(long, struct sockaddr *, long *);
  14. *
  15. *   FUNCTION
  16.  
  17. *        The  argument  s  is a  socket  that  has  been created with
  18. *        socket(), bound to an  address  with bind(), and  is listen-
  19. *        ing for connections after a listen().  accept() extracts the
  20. *        first  connection  on  the  queue  of  pending  connections,
  21. *        creates a new socket with the same properties of s and allo-
  22. *        cates a new socket descriptor for the socket.  If no pending
  23. *        connections are present on the  queue, and the socket is not
  24. *        marked  as non-blocking, accept() blocks the caller  until a
  25. *        connection is present.  If the socket is marked non-blocking
  26. *        and  no  pending  connections  are  present  on  the  queue,
  27. *        accept() returns  an error as described below.  The accepted
  28. *        socket is used to read and write data to and from the socket
  29. *        which connected to  this one; it is not used to  accept more
  30. *        connections.  The original socket s remains open for accept-
  31. *        ing further connections.
  32. *
  33. *        The argument addr is a result parameter that  is  filled  in
  34. *        with  the  address of the connecting entity, as known to the
  35. *        communications layer.  The exact format of the addr  parame-
  36. *        ter  is  determined by the domain in which the communication
  37. *        is occurring.  The addrlen is a value-result  parameter;  it
  38. *        should  initially  contain the amount of space pointed to by
  39. *        addr; on return it will contain the actual length (in bytes)
  40. *        of   the   address   returned.    This  call  is  used  with
  41. *        connection-based socket types, currently with SOCK_STREAM.
  42. *
  43. *        It is possible to select() a socket  for  the  purposes  of
  44. *        doing an accept() by selecting it for read.
  45. *
  46. *   RETURN VALUES
  47. *        accept() returns a non-negative descriptor for the  accepted
  48. *        socket on success.  On failure, it returns -1 and sets errno
  49. *        to indicate the error.
  50. *
  51. *   ERRORS
  52. *        EBADF        - The descriptor is invalid.
  53. *
  54. *        EINTR        - The operation was interrupted by a break 
  55. *                       signal.
  56. *        EOPNOTSUPP   - The referenced socket is not of type
  57. *                       SOCK_STREAM.
  58. *
  59. *        EWOULDBLOCK  - The socket is marked non-blocking and no con-
  60. *                       nections are present to be accepted.
  61. *
  62. *   SEE ALSO
  63. *        bind(), connect(), listen(), select(), SetSocketSignals(),
  64. *        socket()
  65. *****************************************************************************
  66. *
  67. */
  68.  
  69. /****** bsdsocket.library/bind **********************************************
  70. *
  71. *   NAME
  72. *        bind - bind a name to a socket
  73. *
  74. *   SYNOPSIS
  75. *        #include <sys/types.h>
  76. *        #include <sys/socket.h>
  77. *
  78. *        success = bind(s, name, namelen)
  79. *        D0             D0 A0    D1
  80. *
  81. *        long bind(long, struct sockaddr *, long);
  82. *
  83. *   FUNCTION
  84. *        bind() assigns a name to an unnamed socket.  When  a  socket
  85. *        is created with socket(2) it exists in a name space (address
  86. *        family) but has no name assigned.  bind() requests that  the
  87. *        name pointed to by name be assigned to the socket.
  88. *
  89. *   RETURN VALUES
  90. *        0  - on success.
  91. *
  92. *        -1 - on failure and sets errno to indicate the error.
  93. *
  94. *   ERRORS
  95. *        EACCES            - The requested address is protected,  and
  96. *                            the  current user has inadequate permis-
  97. *                            sion to access it.
  98. *
  99. *        EADDRINUSE        - The specified address is already in use.
  100. *
  101. *        EADDRNOTAVAIL     - The specified address is  not  available
  102. *                            from the local machine.
  103. *
  104. *        EBADF             - s is not a valid descriptor.
  105. *
  106. *        EINVAL            - namelen is  not  the  size  of  a  valid
  107. *                            address  for  the specified address fam-
  108. *                            ily.
  109. *
  110. *                            The  socket  is  already  bound  to   an
  111. *                            address.
  112. *
  113. *   SEE ALSO
  114. *        connect(), getsockname(), listen(), socket()
  115. *
  116. *   NOTES
  117. *        The rules used in name binding  vary  between  communication
  118. *        domains.
  119. *****************************************************************************
  120. *
  121. */
  122.  
  123.  
  124. /****** bsdsocket.library/CloseSocket ***************************************
  125. *
  126. *   NAME
  127. *        CloseSocket - delete a socket descriptor
  128. *
  129. *   SYNOPSIS
  130. *        success = CloseSocket(s)
  131. *        D0                    D0
  132. *
  133. *        long CloseSocket(long);
  134. *
  135. *   FUNCTION 
  136. *        CloseSocket() deletes  a  descriptor  from the  library base
  137. *        socket reference table.   If s is the last reference  to the
  138. *        underlying object, then the object  will  be deactivated and
  139. *        socket  (see socket()),  associated naming  information  and
  140. *        queued data are discarded.
  141. *
  142. *        All sockets are automatically closed when the socket library
  143. *        is closed, but closing sockets as soon as possible is
  144. *        recommended to save system resources.
  145. *
  146. *   RETURN VALUES
  147. *         0   on success.
  148. *
  149. *        -1   on failure and sets errno to indicate the error.
  150. *
  151. *   ERRORS
  152. *        EBADF             - s is not an active socket descriptor.
  153. *
  154. *        EINTR             - linger on close was interrupted.
  155. *                            The socket is closed, however.
  156. *
  157. *   SEE ALSO
  158. *        accept(), SocketBaseTagList(), shutdown(), socket(),
  159. *        exec.library/CloseLibrary()
  160. *****************************************************************************
  161. *
  162. */
  163.  
  164.  
  165.  
  166. /****** bsdsocket.library/connect *******************************************
  167. *
  168. *   NAME
  169. *        connect - initiate a connection on a socket
  170. *   
  171. *   SYNOPSIS
  172. *        #include <sys/types.h>
  173. *        #include <sys/socket.h>
  174. *   
  175. *        success = connect(s, name, namelen)
  176. *        D0                D0 A0    D1
  177. *   
  178. *        long connect(long, struct sockaddr *, long);
  179. *   
  180. *   FUNCTION
  181. *        The parameter s is a socket.  If it  is of  type SOCK_DGRAM,
  182. *        then  this call specifies the peer with which the  socket is
  183. *        to be associated;  this address  is that  to which datagrams
  184. *        are  to be sent, and  the only address from which  datagrams
  185. *        are to be received.  If it is of type SOCK_STREAM, then this
  186. *        call attempts  to make a connection  to another socket.  The
  187. *        other socket is specified by name which is an address in the
  188. *        communications space of  the  socket.   Each  communications
  189. *        space interprets the  name parameter in  its  own way.  Gen-
  190. *        erally, stream sockets may successfully connect() only once;
  191. *        datagram sockets may use connect() multiple  times to change
  192. *        their association.  Datagram sockets may dissolve the  asso-
  193. *        ciation by connecting to  an invalid address, such as a null
  194. *        address.
  195. *   
  196. *   RETURN VALUES
  197. *         0   on success.
  198. *   
  199. *        -1   on failure and sets errno to indicate the error.
  200. *   
  201. *   ERRORS
  202. *        EADDRINUSE        - The address is already in use.
  203. *   
  204. *        EADDRNOTAVAIL     - The specified address is  not  available
  205. *                            on the remote machine.
  206. *   
  207. *        EAFNOSUPPORT      - Addresses in the specified address  fam-
  208. *                            ily cannot be used with this socket.
  209. *   
  210. *        EALREADY          - The socket is non-blocking and a  previ-
  211. *                            ous  connection attempt has not yet been
  212. *                            completed.
  213. *   
  214. *        EBADF             - s is not a valid descriptor.
  215. *   
  216. *        ECONNREFUSED      - The attempt to  connect  was  forcefully
  217. *                            rejected.   The  calling  program should
  218. *                            CloseSocket() the socket descriptor, and
  219. *                            issue another socket()  call to obtain a
  220. *                            new descriptor before attempting another
  221. *                            connect() call.
  222. *   
  223. *        EINPROGRESS       - The socket is non-blocking and the  con-
  224. *                            nection cannot be completed immediately.
  225. *                            It is possible to select()  for  comple-
  226. *                            tion  by  selecting the socket for writ-
  227. *                            ing.
  228. *   
  229. *        EINTR             - The operation was interrupted by a break 
  230. *                            signal.
  231. *        EINVAL            - namelen is  not  the  size  of  a  valid
  232. *                            address  for  the specified address fam-
  233. *                            ily.
  234. *   
  235. *        EISCONN             The socket is already connected.
  236. *   
  237. *        ENETUNREACH       - The network is not reachable  from  this
  238. *                            host.
  239. *   
  240. *        ETIMEDOUT         - Connection   establishment   timed   out
  241. *                            without establishing a connection.
  242. *        
  243. *   SEE ALSO
  244. *        accept(), CloseSocket(), connect(), getsockname(), select(),
  245. *        socket()
  246. *****************************************************************************
  247. *
  248. */
  249.  
  250.  
  251. /****** bsdsocket.library/Dup2Socket *****************************************
  252. *
  253. *   NAME
  254. *       Dup2Socket - duplicate a socket descriptor
  255. *
  256. *   SYNOPSIS
  257. *
  258. *       newfd = Dup2Socket(fd1, fd2)
  259. *       D0                 D0   D1
  260. *
  261. *       long Dup2Socket(long, long);
  262. *
  263. *   DESCRIPTION
  264. *       Dup2Socket() duplicates an existing socket descriptor. 
  265. *       the argument fd1 is small non-negative value that indexes
  266. *       the socket on SocketBase descriptor table. The value must
  267. *       be less than the size of the table, which is returned by
  268. *       getdtablesize(). fd2 specifies the desired value of the new
  269. *       descriptor. If descriptor fd2 is already in use, it is 
  270. *       first deallocated as if it were closed by CloseSocket(). If
  271. *       the value if fd2 is -1, the new descriptor used and returned
  272. *       is the lowest numbered descriptor that is not currently in 
  273. *       use by the SocketBase.
  274. *
  275. *       Dup2Socket() has also an feature to mark a file descriptor as
  276. *       being used. If fd1 is given as -1, fd2 is marked as being used
  277. *       socket descriptor table and it won't be allocated for any
  278. *       socket. This mark can be removed using CloseSocket() call.
  279. *
  280. *   RETURN VALUES
  281. *       Dup2Socket() returns a new descriptor on  success. On failure
  282. *       -1 is returned and errno is set to indicate the error.
  283. *
  284. *   ERRORS
  285. *       EBADF          fd1 or fd2 is not a valid active descriptor.
  286. *
  287. *       EMFILE         Too many descriptors are active.
  288. *
  289. *   SEE ALSO
  290. *       accept(), CloseSocket(), getdtablesize(), SocketBaseTagList(),
  291. *       socket()
  292. *
  293. *****************************************************************************
  294. *
  295. */
  296.  
  297.  
  298. /****** bsdsocket.library/getpeername ***************************************
  299. *
  300. *   NAME
  301. *        getpeername - get name of connected peer
  302. *
  303. *   SYNOPSIS
  304. *        success =  getpeername(s, name, namelen)
  305. *        D0                     D0 A0    A1
  306. *
  307. *        long getpeername(long, struct sockaddr *, long *);
  308. *
  309. *   FUNCTION
  310. *        getpeername() returns the name  of  the  peer  connected  to
  311. *        socket  s.   The long  pointed  to  by the namelen parameter
  312. *        should be  initialized  to  indicate  the  amount  of  space
  313. *        pointed  to  by name.  On return it contains the actual size
  314. *        of the name returned (in bytes).  The name is  truncated  if
  315. *        the buffer provided is too small.
  316. *
  317. *   RETURN VALUE
  318. *        A 0 is returned if the call succeeds, -1 if it fails.
  319. *
  320. *   ERRORS
  321. *        EBADF        - The argument s is not a valid descriptor.
  322. *
  323. *        ENOBUFS      - Insufficient resources were available in  the
  324. *                       system to perform the operation.
  325. *
  326. *        ENOTCONN     - The socket is not connected.
  327. *
  328. *   SEE ALSO
  329. *        accept(), bind(), getsockname(), socket()
  330. *****************************************************************************
  331. *
  332. */
  333.  
  334.  
  335. /****** bsdsocket.library/getsockname ***************************************
  336. *
  337. *   NAME
  338. *        getsockname - get socket name
  339. *
  340. *   SYNOPSIS
  341. *
  342. *        success = getsockname(s, name, namelen)
  343. *        D0                    D0 A0    A1
  344. *
  345. *        long getsockname(long, struct sockaddr *, long *);
  346. *
  347. *   FUNCTION
  348. *        getsockname() returns the current  name  for  the  specified
  349. *        socket.   The  namelen  parameter  should  be initialized to
  350. *        indicate the amount of space pointed to by name.  On  return
  351. *        it contains the actual size of the name returned (in bytes).
  352. *
  353. *   DIAGNOSTICS
  354. *        A 0 is returned if the call succeeds, -1 if it fails.
  355. *
  356. *   ERRORS
  357. *        The call succeeds unless:
  358. *
  359. *        EBADF          s is not a valid descriptor.
  360. *
  361. *        ENOBUFS        Insufficient resources were available in  the
  362. *                       system to perform the operation.
  363. *
  364. *   SEE ALSO
  365. *        bind(), getpeername(), socket()
  366. *****************************************************************************
  367. *
  368. */
  369.  
  370.  
  371. /****** bsdsocket.library/getsockopt ****************************************
  372. *
  373. *   NAME
  374. *        getsockopt, setsockopt - get and set options on sockets
  375. *
  376. *   SYNOPSIS
  377. *        #include <sys/types.h>
  378. *        #include <sys/socket.h>
  379. *
  380. *        success =  getsockopt(s, level, optname, optval, optlen)
  381. *        D0                    D0 D1     D2       A0      A1
  382. *        
  383. *        long getsockopt(long, long, long, caddr_t, long *);
  384. *
  385. *        success =  setsockopt(s, level, optname, optval, optlen)
  386. *        D0                    D0 D1     D2       A0      D3
  387. *        
  388. *        long setsockopt(long, long, long, caddr_t, long);
  389. *
  390. *   FUNCTION
  391. *        getsockopt() and setsockopt() manipulate options  associated
  392. *        with  a socket.  Options may exist at multiple protocol lev-
  393. *        els; they are always present  at  the  uppermost  ``socket''
  394. *        level.
  395. *
  396. *        When manipulating socket options  the  level  at  which  the
  397. *        option resides and the name of the option must be specified.
  398. *        To manipulate options at  the  ``socket''  level,  level  is
  399. *        specified as SOL_SOCKET.  To manipulate options at any other
  400. *        level the protocol number of the appropriate  protocol  con-
  401. *        trolling  the  option is supplied.  For example, to indicate
  402. *        that an option is to be interpreted  by  the  TCP  protocol,
  403. *        level  should  be  set  to  the  protocol number of TCP.
  404. *
  405. *        The parameters optval and optlen are used to  access  option
  406. *        values  for  setsockopt().  For getsockopt() they identify a
  407. *        buffer in which the value for the requested option(s) are to
  408. *        be  returned.   For  getsockopt(),  optlen is a value-result
  409. *        parameter, initially  containing  the  size  of  the  buffer
  410. *        pointed to by optval, and modified on return to indicate the
  411. *        actual size of the value returned.  If no option value is to
  412. *        be supplied or returned, optval may be supplied as 0.
  413. *
  414. *        optname and any specified options are  passed  uninterpreted
  415. *        to  the appropriate protocol module for interpretation.  The
  416. *        include  file  <sys/socket.h>   contains   definitions   for
  417. *        ``socket'' level options, described below.  Options at other
  418. *        protocol  levels  vary  in  format  and  name.
  419. *
  420. *        Most socket-level options take an int parameter for  optval.
  421. *        For setsockopt(), the parameter should be non-zero to enable
  422. *        a boolean option, or zero if the option is to  be  disabled.
  423. *
  424. *        SO_LINGER   uses  a  struct  linger  parameter,  defined  in
  425. *        <sys/socket.h>, which specifies the  desired  state  of  the
  426. *        option and the linger interval (see below).
  427. *
  428. *        The following options are recognized at  the  socket  level.
  429. *        Except  as noted, each may be examined with getsockopt() and
  430. *        set with setsockopt().
  431. *
  432. *             SO_DEBUG          - toggle   recording   of   debugging
  433. *                                 information
  434. *             SO_REUSEADDR      - toggle local address reuse
  435. *             SO_KEEPALIVE      - toggle keep connections alive
  436. *             SO_DONTROUTE      - toggle routing bypass for  outgoing
  437. *                                 messages
  438. *             SO_LINGER         - linger on close if data present
  439. *             SO_BROADCAST      - toggle   permission   to   transmit
  440. *                                 broadcast messages
  441. *             SO_OOBINLINE      - toggle  reception  of   out-of-band
  442. *                                 data in band
  443. *             SO_SNDBUF         - set buffer size for output
  444. *             SO_RCVBUF         - set buffer size for input
  445. *             SO_TYPE           - get the type  of  the  socket  (get
  446. *                                 only)
  447. *             SO_ERROR          - get and clear error on  the  socket
  448. *                                 (get only)
  449. *
  450. *        SO_DEBUG  enables  debugging  in  the  underlying   protocol
  451. *        modules.   SO_REUSEADDR  indicates  that  the  rules used in
  452. *        validating addresses supplied in a bind() call should allow
  453. *        reuse of local addresses.  SO_KEEPALIVE enables the periodic
  454. *        transmission of messages on a connected socket.  Should  the
  455. *        connected  party fail to respond to these messages, the con-
  456. *        nection is considered broken. If  the  process  is
  457. *        waiting in select() when the connection is broken, select()
  458. *        returns true for any read or write events selected  for  the
  459. *        socket.    SO_DONTROUTE  indicates  that  outgoing  messages
  460. *        should bypass the  standard  routing  facilities.   Instead,
  461. *        messages  are  directed to the appropriate network interface
  462. *        according to the network portion of the destination address.
  463. *
  464. *        SO_LINGER controls the action taken when unsent messags  are
  465. *        queued  on  socket and a CloseSocket() is performed.  If the
  466. *        socket promises reliable delivery of data and  SO_LINGER  is
  467. *        set,  the  system  will  block  the  process  on the close
  468. *        attempt until it is able to transmit the data  or  until  it
  469. *        decides  it  is unable to deliver the information (a timeout
  470. *        period, in seconds, termed the linger interval, is specified
  471. *        in the set- sockopt() call when SO_LINGER is requested).  If
  472. *        SO_LINGER  is  disabled and a CloseSocket()  is  issued, the
  473. *        system will process the  close  in  a manner that allows the
  474. *        process to continue as quickly as possible.
  475. *
  476. *        The option SO_BROADCAST requests permission to  send  broad-
  477. *        cast  datagrams  on  the socket.  Broadcast was a privileged
  478. *        operation in earlier versions of the system.  With protocols
  479. *        that  support  out-of-band  data,  the  SO_OOBINLINE  option
  480. *        requests that out-of-band data be placed in the normal  data
  481. *        input  queue  as  received;  it will then be accessible with
  482. *        recv() or read() calls without the MSG_OOB flag.   SO_SNDBUF
  483. *        and  SO_RCVBUF are options to adjust the normal buffer sizes
  484. *        allocated for output and input buffers,  respectively.   The
  485. *        buffer size may be increased for high-volume connections, or
  486. *        may be decreased to limit the possible backlog  of  incoming
  487. *        data.   The system places an absolute limit on these values.
  488. *        Finally, SO_TYPE and SO_ERROR are  options  used  only  with
  489. *        getsockopt().   SO_TYPE returns the type of the socket, such
  490. *        as SOCK_STREAM; it is useful for servers that inherit  sock-
  491. *        ets  on  startup.  SO_ERROR returns any pending error on the
  492. *        socket and clears the error status.  It may be used to check
  493. *        for asynchronous errors on connected datagram sockets or for
  494. *        other asynchronous errors.
  495. *
  496. *   RETURN VALUES
  497. *         0 - on success.
  498. *
  499. *        -1 - on failure and set errno to indicate the error.
  500. *
  501. *   ERRORS
  502. *        EBADF             - s is not a valid descriptor.
  503. *
  504. *        ENOPROTOOPT       - The option is unknown at the level indi-
  505. *                            cated.
  506. *
  507. *   SEE ALSO
  508. *        IoctlSocket(), socket()
  509. *
  510. *   BUGS
  511. *        Several of the socket options should  be  handled  at  lower
  512. *        levels of the system.
  513. *****************************************************************************
  514. *
  515. */
  516.  
  517.  
  518. /****** bsdsocket.library/IoctlSocket ***************************************
  519. *
  520. *   NAME
  521. *        IoctlSocket - control sockets
  522. *
  523. *   SYNOPSIS
  524. *
  525. *        #include <sys/types.h>
  526. *        #include <sys/ioctl.h>
  527. *
  528. *        value = IoctlSocket(fd, request, arg)
  529. *        D0            D0  D1       A0
  530. *
  531. *        long IoctlSocket(long, long, caddr_t);
  532. *
  533. *   FUNCTION
  534. *        IoctlSocket() performs a special function on the object referred
  535. *        to by the open  socket descriptor fd. Note: the setsockopt()
  536. *        call (see getsockopt()) is the primary  method for operating
  537. *        on sockets  as such, rather than on the underlying  protocol
  538. *        or network interface.
  539. *
  540. *        For most IoctlSocket() functions, arg is a pointer to data to
  541. *        be used by the  function  or to be filled in by the function.
  542. *        Other functions may ignore arg or may treat it directly as a
  543. *        data item; they may, for example, be passed an int value.
  544. *
  545. *        The following requests are supported:
  546. *
  547. *
  548. *        FIOASYNC            The argument is a  pointer  to  a  long.
  549. *                            Set  or  clear asynchronous I/O.  If the
  550. *                            value of that  long is  a  1  (one)  the
  551. *                            descriptor  is set for asynchronous I/O.
  552. *                            If the value of that long is a  0 (zero)
  553. *                            the  descriptor is cleared for asynchro-
  554. *                            nous I/O.
  555. *
  556. *        FIOCLEX
  557. *        FIONCLEX            Ignored, no use for close-on-exec flag
  558. *                            in Amiga.
  559. *
  560. *        FIOGETOWN
  561. *        SIOCGPGRP           The argument is pointer to struct Task*.
  562. *                            Set the value of that pointer to the 
  563. *                            Task that  is  receiving SIGIO or SIGURG
  564. *                            signals for  the  socket  referred to by
  565. *                            the descriptor passed to IoctlSocket().
  566. *
  567. *        FIONBIO             The argument is a  pointer  to  a  long.
  568. *                            Set  or  clear non-blocking I/O.  If the
  569. *                            value of that  long is  a  1  (one)  the
  570. *                            descriptor  is set for non-blocking I/O.
  571. *                            If the value of that long is a  0 (zero)
  572. *                            the   descriptor  is  cleared  for  non-
  573. *                            blocking I/O.
  574. *
  575. *        FIONREAD            The argument is a  pointer  to  a  long.
  576. *                            Set the value of that long to the number
  577. *                            of immediately readable characters  from
  578. *                            the socket fd.
  579. *
  580. *        FIOSETOWN
  581. *        SIOCSPGRP           The argument is pointer to struct Task*,
  582. *                            pointer  to  the task  that will subseq-
  583. *                            uently receive  SIGIO or  SIGURG signals
  584. *                            for   the  socket  referred  to  by  the
  585. *                            descriptor passed.
  586. *
  587. *        SIOCCATMARK         The argument is a pointer to a long.
  588. *                            Set the value of that long to 1 if the
  589. *                            read pointer for the socket referred to
  590. *                            by the descriptor passed to
  591. *                            IoctlSocket() points to a mark in the
  592. *                            data stream for an out-of-band message,
  593. *                            and to 0 if it does not point to a mark.
  594. *
  595. *
  596. *   RETURN VALUES
  597. *        IoctlSocket() returns 0 on success for most requests.   Some 
  598. *        specialized requests may return non-zero values on success; On  
  599. *        failure,  IoctlSocket() returns -1 and sets errno to indicate
  600. *        the error.
  601. *
  602. *   ERRORS
  603. *        EBADF          fd is not a valid descriptor.
  604. *
  605. *        EINVAL         request or arg is not valid.
  606. *
  607. *        IoctlSocket() will also fail if the object on which the function
  608. *        is  being performed detects an error. In this case, an error
  609. *        code specific  to  the  object  and  the  function  will  be
  610. *        returned.
  611. *
  612. *   SEE ALSO
  613. *        getsockopt(), SocketBaseTagList(), setsockopt()
  614. *****************************************************************************
  615. *
  616. */
  617.  
  618.  
  619. /****** bsdsocket.library/listen ********************************************
  620. *   NAME
  621. *        listen - listen for connections on a socket
  622. *
  623. *   SYNOPSIS
  624. *        success = listen(s, backlog)
  625. *        D0               D0 D1
  626. *
  627. *        long listen(long, long);
  628. *
  629. *   FUNCTION
  630. *        To accept  connections,  a  socket  is  first  created  with
  631. *        socket(),  a  backlog for incoming connections is specified
  632. *        with listen() and then the  connections  are  accepted  with
  633. *        accept().   The  listen()  call  applies only to socket of
  634. *        type SOCK_STREAM.
  635. *
  636. *        The backlog parameter defines the maximum length  the  queue
  637. *        of pending connections may grow to.  If a connection request
  638. *        arrives with the queue full the client will receive an error
  639. *        with an indication of ECONNREFUSED.
  640. *
  641. *   RETURN VALUES
  642. *         0    on success.
  643. *
  644. *        -1    on failure and sets errno to indicate the error.
  645. *
  646. *   ERRORS
  647. *        EBADF             - s is not a valid descriptor.
  648. *
  649. *        EOPNOTSUPP        - The socket is not of a  type  that  sup-
  650. *                            ports listen().
  651. *
  652. *   SEE ALSO
  653. *        accept(), connect(), socket()
  654. *
  655. *   BUGS
  656. *        The backlog is currently limited (silently) to 5.
  657. *****************************************************************************
  658. *
  659. */
  660.  
  661.  
  662. /****** bsdsocket.library/recv **********************************************
  663. *   NAME
  664. *        recv, recvfrom, - receive a message from a socket
  665. *
  666. *   SYNOPSIS
  667. *        #include <sys/types.h>
  668. *        #include <sys/socket.h>
  669. *
  670. *       nbytes = recv(s, buf, len, flags)
  671. *       D0            D0 A0   D1   D2
  672. *
  673. *       long recv(long, char *, long, long);
  674. *
  675. *       nbytes = recvfrom(s, buf, len, flags, from, fromlen)
  676. *       D0                D0 A0   D1   D2     A1    A2
  677. *
  678. *       long recvfrom(long, char *, long, long, 
  679. *                        struct sockaddr *, long *);
  680. *
  681. *   FUNCTION
  682. *        s is a socket created with socket().  recv() and recvfrom(),
  683. *        are used  to  receive messages from  another socket.  recv()
  684. *        may  be  used  only on a connected socket  (see  connect()),
  685. *        while  recvfrom() may be used  to receive data  on a  socket
  686. *        whether it is in a connected state or not.
  687. *
  688. *        If from is not a NULL pointer, the  source  address  of  the
  689. *        message  is filled in.  fromlen is a value-result parameter,
  690. *        initialized to the size of the buffer associated with  from,
  691. *        and  modified  on  return to indicate the actual size of the
  692. *        address  stored  there.   The  length  of  the  message   is
  693. *        returned.   If  a message is too long to fit in the supplied
  694. *        buffer, excess bytes may be discarded depending on the  type
  695. *        of socket the message is received from (see socket()).
  696. *
  697. *        If no messages are available at the socket, the receive call
  698. *        waits  for  a  message  to arrive, unless the socket is non-
  699. *        blocking (see IoctlSocket()) in which case -1  is  returned
  700. *        with the external variable errno set to EWOULDBLOCK.
  701. *
  702. *        The select() call may be used to determine when  more  data
  703. *        arrive.
  704. *
  705. *        The flags parameter is formed by ORing one or  more  of  the
  706. *        following:
  707. *
  708. *        MSG_OOB      - Read any "out-of-band" data  present  on  the
  709. *                       socket,  rather  than  the  regular "in-band"
  710. *                       data.
  711. *
  712. *        MSG_PEEK     - "Peek" at the data present on the socket; the
  713. *                       data  are returned, but not consumed, so that
  714. *                       a subsequent receive operation will  see  the
  715. *                       same data.
  716. *
  717. *   RETURN VALUES
  718. *        These calls return the number of bytes received, or -1 if an
  719. *        error occurred.
  720. *
  721. *   ERRORS
  722. *        EBADF             - s is an invalid descriptor.
  723. *
  724. *        EINTR             - The operation was interrupted by a break 
  725. *                            signal.
  726. *        EWOULDBLOCK       - The socket is  marked  non-blocking  and
  727. *                            the requested operation would block.
  728. *
  729. *   SEE ALSO
  730. *        connect(), getsockopt(), IoctlSocket(), select(), send(),
  731. *        SocketBaseTagList(), socket()
  732. *****************************************************************************
  733. *
  734. */
  735.  
  736. #define NOTEX
  737. /****** bsdsocket.library/recvfrom ******************************************
  738. *
  739. *   SEE ALSO
  740. *        recv()
  741. *****************************************************************************
  742. *
  743. */
  744.  
  745.  
  746. /****** bsdsocket.library/select ********************************************
  747. *
  748. *   NAME
  749. *        select -- synchronous I/O multiplexing (stub/inline function)
  750. *        WaitSelect -- select() with Amiga Wait() function.
  751. *
  752. *   SYNOPSIS
  753. *        #include <sys/types.h>
  754. *        #include <sys/time.h>
  755. *
  756. *        n = select (nfds, readfds, writefds, exceptfds, timeout)
  757. *
  758. *        long select(long, fd_set *, fd_set *, fd_set *, 
  759. *                    struct timeval *);
  760. *
  761. *        n = WaitSelect (nfds, readfds, writefds, exceptfds, timeout,
  762. *        D0              D0    A0       A1        A2         A3
  763. *                    sigmp)
  764. *                    D1
  765. *
  766. *        long WaitSelect(long, fd_set *, fd_set *, fd_set *, 
  767. *                        struct timeval *, long *);
  768. *
  769. *        FD_SET (fd, &fdset)
  770. *        FD_CLR (fd, &fdset)
  771. *        FD_ISSET (fd, &fdset)
  772. *        FD_ZERO (&fdset)
  773. *        long fd;
  774. *        fd_set fdset;
  775. *
  776. *   DESCRIPTION
  777. *        select() examines the socket descriptor sets whose addresses
  778. *        are passed in readfds,  writefds,  and exceptfds  to  see if
  779. *        some of their descriptors are ready  for reading,  ready for
  780. *        writing,  or have an exceptional condition pending.  nfds is
  781. *        the  number  of bits to be checked in  each  bit  mask  that
  782. *        represent a file descriptor; the descriptors from 0  through
  783. *        (nfds - 1) in the descriptor sets  are examined.  On return,
  784. *        select()  replaces  the  given descriptor sets  with subsets
  785. *        consisting of  those descriptors  that  are  ready  for  the
  786. *        requested operation.  The total number  of ready descriptors
  787. *        in all the sets is returned.
  788. *
  789. *        WaitSelect() also takes a signal mask which is waited during
  790. *        normal select() operation. If one of these singals is recei-
  791. *        ved,  WaitSelect() returns  and has  re-set  the signal mask
  792. *        to return those signals that  have arrived.  Normal select()
  793. *        return values are returned.
  794. *
  795. *        The descriptor sets are stored as bit fields  in  arrays  of
  796. *        integers.   The following macros are provided for manipulat-
  797. *        ing such descriptor sets:  FD_ZERO  (&fdset)  initializes  a
  798. *        descriptor  set  fdset to the null set.  FD_SET(fd, &fdset )
  799. *        includes a particular descriptor fd  in  fdset.   FD_CLR(fd,
  800. *        &fdset)  removes  fd  from  fdset.   FD_ISSET(fd, &fdset) is
  801. *        nonzero if fd is a member of  fdset,  zero  otherwise.   The
  802. *        behavior  of these macros is undefined if a descriptor value
  803. *        is less than zero or greater than or  equal  to  FD_SETSIZE,
  804. *        which  is  normally  at least equal to the maximum number of
  805. *        descriptors supported by the system.
  806. *
  807. *        If timeout is not a NULL pointer,  it  specifies  a  maximum
  808. *        interval  to wait for the selection to complete.  If timeout
  809. *        is a NULL  pointer,  the  select  blocks  indefinitely.   To
  810. *        effect  a  poll,  the  timeout argument should be a non-NULL
  811. *        pointer, pointing to a zero-valued timeval structure.
  812. *
  813. *        Any of readfds, writefds, and exceptfds may be given as NULL
  814. *        pointers if no descriptors are of interest.
  815. *
  816. *        Selecting true for reading on a socket descriptor upon which
  817. *        a  listen() call has been performed indicates that a subse-
  818. *        quent accept() call on that descriptor will not block.
  819. *
  820. *   RETURN VALUES
  821. *        select() returns a non-negative value on success. A positive
  822. *        value indicates the number of ready descriptors in the
  823. *        descriptor sets. 0 indicates that the time limit referred to
  824. *        by timeout expired or that the operation was interrupted
  825. *        either by a break signal or by arrival of a signal specified
  826. *        in *sigmp. On failure, select() returns -1, sets errno to
  827. *        indicate the error, and the descriptor sets are not changed.
  828. *
  829. *   ERRORS
  830. *        EBADF        - One  of  the  descriptor  sets  specified  an
  831. *                       invalid descriptor.
  832. *
  833. *        EINTR        - one of the signals in SIGINTR  mask (see Set-
  834. *                       SocketSignals())   is  set  and  it  was  not
  835. *                       requested in WaitSelect() call.
  836. *
  837. *        EINVAL       - A component of the pointed-to time  limit  is
  838. *                       outside  the  acceptable range: t_sec must be
  839. *                       between 0 and 10^8, inclusive. t_usec must be
  840. *                       greater  than  or  equal  to 0, and less than
  841. *                       10^6.
  842. *
  843. *   SEE ALSO
  844. *        accept(),  connect(), getdtablesize(), listen(), recv(),
  845. *        send(), SetDTableSize(), SetSocketSignals()
  846. *
  847. *   NOTES
  848. *        Under rare  circumstances,  select()  may  indicate  that  a
  849. *        descriptor  is  ready for writing when in fact an attempt to
  850. *        write would block.  This  can  happen  if  system  resources
  851. *        necessary  for  a  write are exhausted or otherwise unavail-
  852. *        able.  If an application deems it critical that writes to  a
  853. *        file  descriptor not block, it should set the descriptor for
  854. *        non-blocking I/O using the FIOASYNC request to IoctlSocket().
  855. *
  856. *        Default   system   limit  for  open  socket  descriptors  is
  857. *        currently  64. However,  in  order  to accommodate  programs
  858. *        which might  potentially  use  a larger number of open files
  859. *        with select, it is possible  to  increase this size within a
  860. *        program  by  providing  a  larger definition  of  FD_SETSIZE
  861. *        before    the   inclusion    of   <sys/types.h>    and   use
  862. *        SocketBaseTags(SBTM_SETVAL(SBTC_DTABLESIZE), FD_SETSIZE);
  863. *        call directly after OpenLibrary().
  864. *
  865. *   BUGS
  866. *        select() should probably return the time remaining from  the
  867. *        original  timeout,  if  any,  by modifying the time value in
  868. *        place.  This may be implemented in future  versions  of  the
  869. *        system.   Thus,  it  is  unwise  to  assume that the timeout
  870. *        pointer will be unmodified by the select() call.
  871. *****************************************************************************
  872. *
  873. */
  874.  
  875.  
  876. /****** bsdsocket.library/send **********************************************
  877. *
  878. *   NAME
  879. *        send, sendto - send a message from a socket
  880. *
  881. *   SYNOPSIS
  882. *        #include <sys/types.h>
  883. *        #include <sys/socket.h>
  884. *
  885. *        nbytes = send(s, msg, len, flags)
  886. *        D0            D0 A0   D1   D2
  887. *
  888. *        int send(int, char *, int, int);
  889. *
  890. *        nbytes = sendto(s, msg, len, flags, to, tolen)
  891. *        D0              D0 A0   D1   D2     A1  D3
  892. *
  893. *        int send(int, char *, int, int, struct sockaddr *, int);
  894. *
  895. *   FUNCTION
  896. *        s is a socket created with socket().  send() and sendto() are
  897. *        used  to transmit a message to  another socket. send() may be
  898. *        used  only when the socket  is  in a connected  state,  while
  899. *        sendto() may be used at any time.
  900. *
  901. *        The address of the target  is given by to with tolen specify-
  902. *        ing its size.  The length of the message is given by len.  If
  903. *        the  message is  too  long  to  pass  atomically  through the
  904. *        underlying protocol, then the error EMSGSIZE is returned, and
  905. *        the message is not transmitted.
  906. *
  907. *        No indication of failure to deliver is implicit  in a send().
  908. *        Return values of -1 indicate some locally detected errors.
  909. *
  910. *        If no buffer space is  available at the socket  to  hold  the
  911. *        message  to  be  transmitted,  then  send() normally  blocks,
  912. *        unless the  socket  has been placed in non-blocking I/O mode.
  913. *        The select() call may be used to determine when  it  is  pos-
  914. *        sible to send more data.
  915. *
  916. *        The flags parameter is formed  by ORing  one  or  more of the
  917. *        following:
  918. *
  919. *        MSG_OOB           - Send  ``out-of-band''  data  on  sockets
  920. *                            that  support this notion.  The underly-
  921. *                            ing protocol must  also  support  ``out-
  922. *                            of-band''    data.     Currently,   only
  923. *                            SOCK_STREAM  sockets  created   in   the
  924. *                            AF_INET  address  family support out-of-
  925. *                            band data.
  926. *
  927. *        MSG_DONTROUTE     - The SO_DONTROUTE option is turned on for
  928. *                            the  duration of the operation.  This is
  929. *                            usually used only by diagnostic or rout-
  930. *                            ing programs.
  931. *
  932. *   RETURN VALUES
  933. *        On success, these functions return the number of bytes sent.
  934. *        On  failure,  they  return  -1 and set errno to indicate the
  935. *        error.
  936. *
  937. *   ERRORS
  938. *        EBADF             - s is an invalid descriptor.
  939. *
  940. *        EINTR             - The operation was interrupted by a break 
  941. *                             signal.
  942. *        EINVAL            - len is not the size of a  valid  address
  943. *                            for the specified address family.
  944. *
  945. *        EMSGSIZE          - The socket requires that message be sent
  946. *                            atomically,  and the size of the message
  947. *                            to be sent made this impossible.
  948. *
  949. *        ENOBUFS           - The system was  unable  to  allocate  an
  950. *                            internal   buffer.   The  operation  may
  951. *                            succeed when buffers become available.
  952. *
  953. *        ENOBUFS           - The output queue for a network interface
  954. *                            was full.  This generally indicates that
  955. *                            the interface has stopped  sending,  but
  956. *                            may be caused by transient congestion.
  957. *
  958. *        EWOULDBLOCK       - The socket is  marked  non-blocking  and
  959. *                            the requested operation would block.
  960. *
  961. *   SEE ALSO
  962. *        connect(), getsockopt(), recv(), select(), socket()
  963. *****************************************************************************
  964. *
  965. */
  966.  
  967. #define NOTEX
  968. /****** bsdsocket.library/sendto ********************************************
  969. *
  970. *   SEE ALSO
  971. *        send()
  972. *****************************************************************************
  973. *
  974. */
  975.  
  976. #define NOTEX
  977. /****** bsdsocket.library/setsockopt ****************************************
  978. *
  979. *   SEE ALSO
  980. *        getsockopt()
  981. *****************************************************************************
  982. *
  983. */
  984.  
  985.  
  986. /****** bsdsocket.library/shutdown ******************************************
  987. *
  988. *   NAME
  989. *        shutdown - shut down part of a full-duplex connection
  990. *
  991. *   SYNOPSIS
  992. *        success = shutdown(s, how)
  993. *        D0                 D0 D1
  994. *
  995. *        long shutdown(long, long);
  996. *
  997. *   DESCRIPTION
  998. *        The shutdown() call causes all or part of a full-duplex con-
  999. *        nection on the socket associated with s to be shut down.  If
  1000. *        how is 0, then further receives will be disallowed.  If  how
  1001. *        is  1,  then further sends will be disallowed.  If how is 2,
  1002. *        then further sends and receives will be disallowed.
  1003. *
  1004. *   RETURN VALUES
  1005. *         0 - on success.
  1006. *
  1007. *        -1 - on failure and sets errno to indicate the error.
  1008. *
  1009. *   ERRORS
  1010. *        EBADF        - s is not a valid descriptor.
  1011. *
  1012. *        ENOTCONN     - The specified socket is not connected.
  1013. *
  1014. *   SEE ALSO
  1015. *        connect(), socket()
  1016. *
  1017. *   BUGS
  1018. *        The how values should be defined constants.
  1019. *****************************************************************************
  1020. *
  1021. */
  1022.  
  1023.  
  1024. /****** bsdsocket.library/socket ********************************************
  1025. *
  1026. *   NAME
  1027. *        socket - create an endpoint for communication
  1028. *
  1029. *   SYNOPSIS
  1030. *        #include <sys/types.h>
  1031. *        #include <sys/socket.h>
  1032. *
  1033. *        s = socket(domain, type, protocol)
  1034. *        D0          D0     D1    D2
  1035. *
  1036. *        long socket(long, long, long);
  1037. *
  1038. *   FUNCTION
  1039. *        socket() creates an endpoint for communication and returns a
  1040. *        descriptor.
  1041. *
  1042. *        The  domain  parameter  specifies  a  communications  domain
  1043. *        within which communication will take place; this selects the
  1044. *        protocol  family  which should be used.  The protocol family
  1045. *        generally  is  the  same  as  the  address  family  for  the
  1046. *        addresses supplied in later operations on the socket.  These
  1047. *        families  are defined  in the  include file  <sys/socket.h>.
  1048. *        The currently understood formats are
  1049. *
  1050. *                PF_INET - (ARPA Internet protocols)
  1051. *
  1052. *        The socket has the indicated type, which specifies the
  1053. *        semantics of communication.  Currently defined types are:
  1054. *
  1055. *                SOCK_STREAM
  1056. *                SOCK_DGRAM
  1057. *                SOCK_RAW
  1058. *
  1059. *        A  SOCK_STREAM type  provides  sequenced,  reliable, two-way
  1060. *        connection  based   byte  streams.    An   out-of-band  data
  1061. *        transmission  mechanism  may  be  supported.   A  SOCK_DGRAM
  1062. *        socket supports datagrams  (connectionless, unreliable  mes-
  1063. *        sages  of  a  fixed   (typically   small)  maximum  length).
  1064. *        SOCK_RAW   sockets   provide  access  to   internal  network
  1065. *        interfaces.
  1066. *
  1067. *        The protocol specifies a particular protocol to be used with
  1068. *        the socket.  Normally  only a single protocol exists to sup-
  1069. *        port a particular socket type  within a given  protocol fam-
  1070. *        ily.  However, it is possible that many protocols may exist,
  1071. *        in which case a  particular protocol  must be  specified  in
  1072. *        this manner.  The  protocol number to use  is  particular to
  1073. *        the "communication domain" in which communication is to take
  1074. *        place.
  1075. *
  1076. *        Sockets of type SOCK_STREAM  are  full-duplex byte  streams,
  1077. *        similar to pipes.   A  stream socket must be in  a connected
  1078. *        state before any data may be sent or received on it.  A con-
  1079. *        nection  to another socket is created with a connect() call.
  1080. *        Once  connected, data  may be  transferred using send()  and
  1081. *        recv()  or their variant calls.   When  a  session  has been
  1082. *        completed a CloseSocket()  may  be  performed.   Out-of-band
  1083. *        data may also  be transmitted  as  described  in  send() and
  1084. *        received as described in recv().
  1085. *
  1086. *        The communications protocols used to implement a SOCK_STREAM
  1087. *        insure that data is  not lost or  duplicated.  If a piece of
  1088. *        data for  which the peer protocol has buffer space cannot be
  1089. *        successfully transmitted within a reasonable length of time,
  1090. *        then the  connection  is  considered broken  and  calls will
  1091. *        indicate an error with -1 returns and with ETIMEDOUT  as the
  1092. *        specific error code (see Errno()).  The protocols optionally
  1093. *        keep sockets "warm" by  forcing transmissions roughly  every
  1094. *        minute in the absence of other activity.
  1095. *
  1096. *        SOCK_DGRAM  and SOCK_RAW sockets allow sending of  datagrams
  1097. *        to  correspondents  named in send()  calls.   Datagrams  are
  1098. *        generally  received  with  recv(), which  returns  the  next
  1099. *        datagram with its return address.
  1100. *
  1101. *        The operation of  sockets  is  controlled  by  socket  level
  1102. *        options.   These  options  are defined in the file socket.h.
  1103. *        getsockopt() and  setsockopt()  are  used  to  get  and  set
  1104. *        options, respectively.
  1105. *
  1106. *   RETURN VALUES
  1107. *        socket() returns a non-negative descriptor on  success.   On
  1108. *        failure, it returns -1 and sets errno to indicate the error.
  1109. *
  1110. *   ERRORS
  1111. *        EACCES          - Permission to create  a  socket  of  the
  1112. *                          specified   type   and/or   protocol  is
  1113. *                          denied.
  1114. *
  1115. *        EMFILE          - The per-process descriptor table is
  1116. *                          full.
  1117. *
  1118. *        ENOBUFS         - Insufficient buffer space is available.
  1119. *                          The socket cannot be created until suf-
  1120. *                          ficient resources are freed.
  1121. *
  1122. *        EPROTONOSUPPORT - The protocol type or the specified  pro-
  1123. *                          tocol is not supported within this
  1124. *                          domain.
  1125. *
  1126. *        EPROTOTYPE      - The protocol is the wrong type for the
  1127. *                          socket.
  1128. *
  1129. *   SEE ALSO
  1130. *        accept(), bind(), CloseSocket(), connect(), getsockname(),
  1131. *        getsockopt(), IoctlSocket(), listen(), recv(), select(), 
  1132. *        send(), shutdown(), WaitSelect()
  1133. *****************************************************************************
  1134. *
  1135. */
  1136.